package com.yunji.cabinet.device;

import com.yunji.coffee.entity.dto.DeviceInfoDTO;
import com.yunji.system.context.SystemUtil;
import org.redisson.api.RMap;

import java.util.Objects;

/**
 * @author : peter-zhu
 * @date : 2025/1/15 16:33
 * @description : TODO
 **/
public class DeviceInfoCache {

    public static RMap<String, DeviceInfoDTO> map() {
        return SystemUtil.redisson.getMap(DeviceCacheCode.DEVICE_INFO_CACHE_CODE);
    }

    public static void createInfo(DeviceInfoDTO info) {
        map().put(info.getImei(), info);
    }

    public static void removeInfo(String imei) {
        map().remove(imei);
    }

    public static DeviceInfoDTO getInfo(String imei) {
        return map().get(imei);
    }

    public static <T> T getInfo(String imei, Class<T> clazz) {
        return clazz.cast(map().get(imei));
    }

    public static <T> T getInfoByType(String imei, String typeCode) {
        return getInfo(imei, Objects.requireNonNull(ContainerTypeEnum.getClass(typeCode)));
    }
}
